<template>
  <DetailsFormBox :title="dataInfo?.table?.title" :type="route.query.type" :form="data.form" :btns="[
    {
      title: '重置',
      icon: '',
      type: '',
      click: getForm,
    },
    {
      title: '保存',
      icon: '',
      type: 'primary',
      click: (form: any) => {
        saveBtn(form)
      },
    },
  ]" :loading="data.loading" :json="dataInfo">
    <template #default="{ form }">
      <div class="formMain">
        <ElFormItemBox label="客户名称" :prop="`customerName`" isRules>
          <ElInputBox :data="form" dataName="customerName" />
        </ElFormItemBox>
        <ElFormItemBox label="结算方式" :prop="`settlementWay`" isRules>
          <ElRadioBox :data="form" dataName="settlementWay" :options="options.settlementWay" />
        </ElFormItemBox>
        <ElFormItemBox label="快递费用归属" :prop="`courierFeeType`">
          <ElRadioBox :data="form" dataName="courierFeeType" :options="proxy.$optionsArr.courierFeeType" />
        </ElFormItemBox>
        <ElFormItemBox label="是否含税" :prop="`isIncludingTax`" isRules>
          <ElRadioBox :data="form" dataName="isIncludingTax" :options="options.isIncludingTax" />
        </ElFormItemBox>
        <ElFormItemBox label="税率" :prop="`taxRate`" isRules>
          <ElNumberBox :data="form" dataName="taxRate" :max="1" :min="0" />
        </ElFormItemBox>
        <ElFormItemBox label="销售代表" :prop="`belongToSalesman`" isRules>
          <ElSelectBox :data="form" dataName="belongToSalesman" :options="options.personnel" />
        </ElFormItemBox>
        <ElFormItemBox label="客户电话" :prop="`contactMobile`">
          <ElInputBox :data="form" dataName="contactMobile" />
        </ElFormItemBox>
        <ElFormItemBox label="联系人" :prop="`contactPerson`">
          <ElInputBox :data="form" dataName="contactPerson" />
        </ElFormItemBox>
        <ElFormItemBox label="客户地址" :prop="`customerAddress`">
          <AddressBox :data="form" :dataName="{
            province: 'province',
            city: 'city',
            country: 'country',
            address: 'customerAddress',
          }" />
        </ElFormItemBox>
        <ElFormItemBox label="备注" :prop="`customerRemark`">
          <ElInputBox :data="form" dataName="customerRemark" type="textarea" />
        </ElFormItemBox>
      </div>
    </template>
  </DetailsFormBox>
</template>
<script setup lang="ts">
import { useListComponent } from '../pageTs'; // 引入逻辑
const { dataInfo } = useListComponent();
import { reactive, onMounted, getCurrentInstance } from 'vue';
const { proxy } = getCurrentInstance() as any;
const data = reactive({
  loading: false,
  loadingMsg: '',
  form: {
    taxRate: 0.13, // 税率
    courierFeeType: 0, // 快递费用归属，0-客户承担；1-公司承担；2-各自一半，默认0
    isIncludingTax: 0, // 是否含税,0-未税；1-含税，默认0
    customerName: "", // 客户名字
    belongToSalesman: "", // 客户归属销售人员（销售代表）
    contactPerson: "", // 联系人姓名
    contactMobile: "", // 联系电话
    province: "", // 所在省代码
    city: "", // 所在市代码
    country: "", // 所在县代码
    customerAddress: "", // 客户地址
    customerRemark: "", // 客户备注
    settlementWay: 0 // 结算方式：1日结；2月结
  },
});
import { useRoute } from 'vue-router';
// 获取当前路由对象
const route = useRoute();
import { sendMsg } from '@/utils/crossTagMag.ts';
const { options } = useListComponent();
const saveBtn = (form: any) => {
  proxy.$api.OrderBusniess.CreateNewCustomer(form)
    .then((res: any) => {
      _sun()
    })
    .catch(() => { });
  function _sun() {
    proxy.$message('保存成功')
    sendMsg('save', true);
    // getForm()
    window.close();
  }
};
const getForm = (form: any, resetForm: Function) => {
  data.form.province = ''
  data.form.city = ''
  data.form.country = ''
  resetForm()
};
import { getPersonnel } from '@/utils/optionsArr.ts';
onMounted(() => {
  getPersonnel(options, 'personnel') //获取所有员工
});
</script>
